package com.twq.collection.framework.conversions

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

/**
 * Created by tangweiqun on 2017/12/22.
 * java集合与scala集合转化
 */
object Conversions {
  def main(args: Array[String]): Unit = {
    import scala.collection.JavaConversions._

    /**
     * 双向转换
     * Iterator <--> java.util.Iterator
     * Iterator <--> java.util.Enumeration
     * Iterable <--> java.util.Iterable
     * Iterable <--> java.util.Collection
     * mutable.Buffer <--> java.util.List
     * mutable.Set <--> java.util.Set
     * mutable.Map <--> java.util.Map
     */
    val jul: java.util.List[Int] = ArrayBuffer(1, 2, 3)

    val buf: mutable.Buffer[Int] = jul

    val m: java.util.Map[String, Int] = mutable.HashMap("abc" -> 1, "hello" -> 2)

    val map: mutable.Map[String, Int] = m

    /*
       单向转换
     * Seq --> java.util.List
     * mutable.Seq --> java.util.List
     * Set --> java.util.Set
     * Map --> java.util.Map
     */

    val javaul: java.util.List[Int] = List(1, 2, 3)
    javaul.add(2)
  }
}
